package org.hellhouse.thehungryslingshot.view;

import org.hellhouse.thehungryslingshot.model.World;

import android.content.Context;
import android.graphics.Canvas;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class Panel extends SurfaceView implements SurfaceHolder.Callback {

	private WorldView worldView;
	private World world;
	@SuppressWarnings("unused")
	private int width;
	@SuppressWarnings("unused")
	private int height;
	@SuppressWarnings("unused")
	private Context context;

	public Panel(Context context, World world) {
		super(context);
		this.context = context;
		this.world = world;
	}

	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {

	}

	public void surfaceCreated(SurfaceHolder holder) {
		if (!worldView.isAlive()) {
			worldView = new WorldView(this);
			worldView.setRunning(true);
			worldView.start();

		}
	}

	public void surfaceDestroyed(SurfaceHolder holder) {
		if (worldView.isAlive()) {
			worldView.setRunning(false);
		}
	}

	public synchronized void doDraw(Canvas canvas) {

	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		@SuppressWarnings("unused")
		float mouseX = event.getX();
		@SuppressWarnings("unused")
		float mouseY = event.getY();
		return super.onTouchEvent(event);
	}

	public boolean isPointInRegion(int pointX, int pointY, int startX,
			int startY, int endX, int endY) {
		return ((pointX > startX && pointX < endX) && (pointY > startY && pointY < endY));
	}
	
	
	public World getWorld() {
		return world;
	}

	public void setWorld(World world) {
		this.world = world;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public void setHeight(int height) {
		this.height = height;
	}

}
